feat: join and fund an agent wallet in one transaction - #1409
Merged
Conversation
Time Submission Status
Submit or update total time with: Add time on top of previous submission with: See available commands to help comply with our Guidelines. |
📝 WalkthroughWalkthroughAdds the public ChangesMAA Join and Fund
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Sequence Diagram(s)sequenceDiagram
participant Caller
participant maa_join_and_fund
participant maa_join
participant maa_dispatch_transfer
Caller->>maa_join_and_fund: rule_id, bridge, amount
maa_join_and_fund->>maa_join: Join rule and derive MAA
maa_join-->>maa_join_and_fund: maa_address
maa_join_and_fund->>maa_dispatch_transfer: Dispatch amount to derived MAA
maa_dispatch_transfer-->>Caller: Return maa_address
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
Author
|
@holdex pr submit-time 4h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
maa_join_and_fund($rule_id, $bridge, $amount), so a funder joins a rule and funds the derived agent wallet in a single transaction instead of a join followed by a separate transfer. Either both legs commit or neither does, so activation can no longer strand a joined-but-unfunded wallet.The node half of the atomic-activation ask:
resolves: https://github.com/trufnetwork/truf-network/issues/1399
A kwil transaction runs exactly one action, so the SDKs cannot compose join + transfer atomically on the client — the two legs can only share a transaction inside one on-chain action. The
joinAndFundAgentAddressSDK wrapper that exposes this (and closes #1399) is the follow-up.What is here
internal/migrations/054-maa-join-fund.sql— the composite action. Leg 1 delegates tomaa_join(all its guards apply: unknown rule, creator-self-join, duplicate join). Leg 2 debits the funder and credits the fresh wallet through 049's existing bridge dispatcher. The whole body runs in the route's nested transaction, so any failure rolls back both legs.tests/streams/maa/join_and_fund_test.go— happy path, input validation, atomicity (insufficient balance and bad bridge each roll the join back), and duplicate-join plus a second funder deriving a distinct wallet.Design notes
.prod.sqltwin. The action names no bridge; it only calls 049's dispatcher, whose mainnet twin already remaps the bridge branches. A scan confirms no bridge alias appears in the file.maa_joinit moves funds, so through themaa_execroute an owner could self-strand into a keyless nested wallet. A restricted agent is blocked by the transfer guard, so no untrusted party can strand or steal; this is a wallet-signed activation call, not an agent action.Worth a look
ifs, notIS NULL OR <= 0. The engine'sORreturns NULL forTRUE OR NULLrather than TRUE, so the combined form skips the guard on a NULL amount and lets it fall through to the transfer. The same dead pattern exists in 049's withdraw guard (atomic-safe, but itsIS NULLhalf never fires) — left untouched here, flagged for a follow-up.Testing
Full
tests/streams/maapackage green, including the four new tests. New migration parses (kwil-cli utils parse).Summary by CodeRabbit
New Features
Tests